package com.sh.rpc.server;

import io.vertx.core.Vertx;

public class VertxHttpService implements HttpServer{

    @Override
    public void doStart(int port) {
        Vertx vertx = Vertx.vertx();

        // 创建一个HTTP服务器  写处理逻辑
        io.vertx.core.http.HttpServer server = vertx.createHttpServer();
/*      版本一
        server.requestHandler( request->{
            // http://localhost:9989/sdfsa
            //                 收到请求：          GET                     /sdfsa
            System.out.println("收到请求： " + request.method() + " " + request.uri());
            // 响应请求
            request.response().putHeader("content-type", "text/plain").end("Hello World!  Vertx");
        });*/

        server.requestHandler( new HttpServerHandler());

        // 启动监听
        server.listen(port, result->{
           if ( result.succeeded() ){  // 启动成功
               System.out.println("HTTP server is listening on port " + result.result().actualPort());
           }else {
               System.out.println("HTTP server failed to start: " + result.cause().getMessage());
           }
        });



    }
}
